<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>
    var map = [{id: 1, connect: [2,3]},
        {id: 2, connect: [1,4,5]}]
    function findWithDepth(start, depth) {
        for(var i = 1;i<map.length;i++){
            if(map[i].id== start){
                for(var j=0;j<map[i].connect.length;j++){
                    console.log(map[i].connect[j]);
                }
            }else{
                for(var i=0;i<map.length;i++){
                    if(map[i].id==start){
                        for(var j=0;j<map[i].connect.length;j++){
                            findwithDepth(map[i].connect[j],depth-1);
                        }
                    }
                }

            }
        }
    }
</script>
</html>